package com.FH.organization.work_flow;

import com.FH.util.ResultDTO;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

/**
 * Created by Administrator on 2016/7/25.
 *
 * 流程管理资源类
 */
@Path("/workflow")
@Produces(MediaType.APPLICATION_JSON)
@RequestScoped
public class WorkFlowResource {

    @EJB
    private WorkFlowDAO workFlowDAO;

//    @GET
//    @Path("/")
//    public ResultDTO getWorkFlowInfo(){
//        return workFlowDAO.getWorkFlowInfo();
//    }



    @GET
    @Path("/{search}&{page}&{size}")
    public ResultDTO getWorkFlowInfo(@PathParam("search") String search, @PathParam("page") String page, @PathParam("size") String size){
        //添加分页查询
        if(null==page||"".equals(page)||"0".equals(page))
        {
            page = "1";	//默认从第1页开始查起
        }/*else
        {
            page =((Integer.parseInt(page)-1)*Integer.parseInt(size))+"";
        }*/
        if(null==size||"".equals(size))
        {
            size = "10";//默认10行数据
        }
        return workFlowDAO.getWorkFlowInfo(search, page, size);
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO addWorkFlowInfo(WorkFlowPullDTO dataDTO){
        return workFlowDAO.addWorkFlowInfo(dataDTO);
    }

    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    @Path("/update")
    public ResultDTO updateWorkFlowInfo(WorkFlowPullDTO dataDTO){
        return workFlowDAO.updateWorkFlowInfo(dataDTO);
    }


    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO editapply(WorkFlowPullDTO dataDTO){
        return workFlowDAO.updataapply(dataDTO);
    }

    @DELETE
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO deleteWorkFlowInfo(WorkFlowPullDTO dataDTO){
        return workFlowDAO.deleteWorkFlowInfo(dataDTO);
    }

    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    @Path("/update/desc")
    public ResultDTO updatedesc(WorkFlowPullDTO dataDTO){
        return workFlowDAO.updatedesc(dataDTO);
    }
}
